﻿@{
    Layout = null;
}

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>登录</title>
    <link href="/Content/bootstrap.min.css" rel="stylesheet" />
    <script src="/Scripts/jquery-1.10.2.min.js"></script>
</head>
<body>
    <div class="container">
        <div class="row" style="margin-top: 100px;">

        </div>
        <div class="row">
            <div class="col-md-4"></div>
            <div class="col-md-4">
                <form id="f1" onsubmit="return fnSubmit();" method="post">
                    <div class="form-group">
                        <label for="n" class="control-label">用户名</label>
                        <input type="text" id="n" name="n" value="" placeholder="用户名" class="form-control" required="required" />
                    </div>
                    <div class="form-group">
                        <label for="p">密&nbsp;&nbsp;码</label>
                        <input type="password" id="p" name="p" value="" placeholder="密码" class="form-control" required="required" />
                    </div>
                    <div class="form-group">
                        <input type="submit" class="btn btn-primary form-control" value="登 录" />
                    </div>
                </form>
                <div class="alert ">

                </div>
            </div>
            <div class="col-md-4">

            </div>
        </div>

    </div>
    <footer></footer>
    <script type="text/javascript">
        var u = '@Html.Raw(ViewBag.ReturnUrl)';
        if (! u) {
            u = '/';
        }
        function fnSubmit() {
            var f = document.getElementById("f1");
            if (f.checkValidity()) {
                var formdata = {
                    "n": f.n.value,
                    "p": f.p.value
                };
                $.post('/login', formdata, function (r) {
                    if (r.code === 0) {
                        //$(".alert").html("OK");
                        //$(".alert").addClass('alert-success');
                        $(".alert").removeClass('alert-danger');
                        location.href = u;
                    } else {
                        $(".alert").html(r.msg);
                        $(".alert").addClass('alert-danger');
                        $(".alert").removeClass('alert-success');
                    }
                    return false;
                });
                return false;
            }

            if (!f.n.checkValidity) {
                f.n.parentElement.classList.add('has-error');
            } else {
                f.n.parentElement.classList.remove('has-error');
            }
            if (!f.p.checkValidity) {
                f.p.parentElement.classList.add('has-error');
            } else {
                f.p.parentElement.classList.remove('has-error');
            }
            return false;
        }

    </script>
</body>
</html>
